package com.zhang.security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author ZhangJZ
 * @create 2022-05-11 22:42
 */
//@Configuration  //注释掉这个配置类了
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
        String pwd = passwordEncoder.encode("123");
        System.out.println(pwd);
        auth.inMemoryAuthentication().withUser("zjz").password(pwd).roles("admin");
    }

    //得把这个组件添加到容器中
    @Bean
    public PasswordEncoder passwoed(){
        return new BCryptPasswordEncoder();
    }
}
